#ifndef NODE_H
#define NODE_H
#include <string>
#include "Log.h"
#include "stopwatch.h"
#include <mutex>
#include <thread>
#include <condition_variable>

#define NODE_DATA    \
    protected:        \
    float nodeValue = 0.0;\
    std::string nodeUint;\
    CLDeviceInfo* deviceinfo;\
    int weight = 10;\
    int errFlag = 0;\
    int timeout = 600;\
    std::mutex mtxWait;\
    std::condition_variable cvWait;

class ImageWidget;
class CLDeviceInfo;
class Node
{
    NODE_DATA
public:
    enum RunningState {
        RunningState_Success,
        RunningState_Failed,
        RunningState_Abort
    };
    enum NodeType {
        NodeTP_Unknown = 0,
        //基础数据处理速度
        NodeTP_DataSpeed,
        //总线速度
        NodeTP_BsSpeed,
        //内存读写性能
        NodeTP_MemRw,
        //内核编译速度
        NodeTP_Kernel,
        //队列延迟时间
        NodeTP_Queue,
        //综合处理能力
        NodeTP_Triad
    };

    explicit Node();
    ~Node();
    virtual bool ignore();
    virtual std::string name();
    virtual std::string describe();
    virtual NodeType nodeType();

    void setDevice(CLDeviceInfo *);
    RunningState run();
    static std::string nodeTypeName(Node::NodeType type);
    float performValue() ;
    std::string unit() ;
    int weightValue();
    void setWeightValue(const int &);
protected:
    virtual bool startup();
    virtual bool perform();
    virtual void shutdown();
    void wait(const size_t &waitTime = 3000);
private:
    void asynRun();
};
#endif
